/**
 * @Author: wangjian
 * 656876071@qq.com
 * @Date: 2024-07-22 11:10:24
 * @LastEditTime: 2024-07-23 11:25:47
 * @FilePath: src/views/sxln/member/Upload.ts
 * @Description:
 */
import {ref} from "vue";
import axios from "axios";
import type {UploadFile} from 'ant-design-vue'

const testUrl: string = "http://127.0.0.1:9008/sxln/file/store/avatar.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240722T061837Z&X-Amz-SignedHeaders=host&X-Amz-Credential=test%2F20240722%2FCN%2Fs3%2Faws4_request&X-Amz-Expires=18000&X-Amz-Signature=8304f74062d2c7beabd14967aba2f986dd40d49df095a888500f2ba658bc38ee";
export default () => {
    const uploadList = ref<object[]>()
    const beforeUpload = (file: any, fileList: any) => {
        // console.log(file,fileList)
        console.log("before upload")
        return true
    }
    const handleChange = ({file}: { file: UploadFile }) => {
        console.log(file.status)
    }

    const customUpload = (e: any) => {
        // 会触发上面的handleChange 事件，file的status会变为uploading
        console.log(e)
        axios.put(testUrl, e.file,{onUploadProgress(progressEvent) {
            console.log(progressEvent)
        },}).then((res: any) => {
            console.log(res.headers.etag)
            // 会触发上面的handleChange 事件，file的status会变为done
            e.onSuccess(res.headers.etag, e)
        }).catch(e => console.error(e))
    }
    return {
        uploadList,
        customUpload,
        beforeUpload,
        handleChange
    }
}